import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _isEmpty from "lodash/isEmpty";
import { queryMapIdpValue } from 'cpaas-front/lib/services/api';
import { getResponse, getCurrentOrganizationId, isTenantRoleLevel, createPagination } from 'utils/utils';
import { queryMenuTree, queryOrganizationMenuTree, checkMenuDirExists as _checkMenuDirExists, queryCode as _queryCode, queryDir, queryOrganizationDir, createDir as _createDir, createOrganizationDir, saveDir as _saveDir, saveOrganizationDir, importMenu as _importMenu, importOrganizationMenu, queryPermissions as _queryPermissions, deleteMenu as _deleteMenu, deleteOrganizationMenu, queryPermissionSetTree as _queryPermissionSetTree, setPermissionSetEnable as _setPermissionSetEnable, queryPermissionsByMenuId as _queryPermissionsByMenuId, queryPermissionsByMenuIdAll, queryLovsByMenuIdAll, queryLovByMenuId as _queryLovByMenuId, assignPermissions as _assignPermissions, deletePermissions as _deletePermissions, queryOrganizationCustomMenu as _queryOrganizationCustomMenu, exportCustomMenu as _exportCustomMenu, // refreshRoutePermissionSet,
queryCopyMenuList as _queryCopyMenuList, copyMenu as _copyMenu, queryLabelList as _queryLabelList, queryMenuLabel as _queryMenuLabel, querySearchLabels as _querySearchLabels // 查询搜索字段标签数据
} from "../services/menuConfigService";
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();

function defineProperty(obj, property, value) {
  Object.defineProperty(obj, property, {
    value: value,
    writable: true,
    enumerable: false,
    configurable: true
  });
}

export default {
  namespace: 'menuConfig',
  state: {
    code: {},
    // 值集集合
    list: {
      // 列表页面数据集合
      dataSource: [],
      // 表格数据
      pagination: {},
      // 分页配置
      flatKey: [] // 用于控制是否全部展开/收起的行数据key集合

    },
    menuPrefixList: [],
    // 菜单前缀
    menuTypeList: [],
    // 菜单类型
    controllerType: [],
    // 权限集控制类型
    customMenu: {
      list: []
    },
    siteLabelList: [],
    tenantLabelList: [],
    searchLabels: [] // 搜索字段标签

  },
  effects: {
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_ref, _ref2) {
      var payload, put, call, lovCodes, code, _code$menuPrefix, menuPrefixList, _code$menuType, menuTypeList, _code$controllerType, controllerType;

      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              put = _ref2.put, call = _ref2.call;
              lovCodes = payload.lovCodes;
              _context.t0 = getResponse;
              _context.next = 6;
              return call(queryMapIdpValue, lovCodes);

            case 6:
              _context.t1 = _context.sent;
              code = (0, _context.t0)(_context.t1);

              if (!code) {
                _context.next = 12;
                break;
              }

              _code$menuPrefix = code.menuPrefix, menuPrefixList = _code$menuPrefix === void 0 ? [] : _code$menuPrefix, _code$menuType = code.menuType, menuTypeList = _code$menuType === void 0 ? [] : _code$menuType, _code$controllerType = code.controllerType, controllerType = _code$controllerType === void 0 ? [] : _code$controllerType;
              _context.next = 12;
              return put({
                type: 'updateStateReducer',
                payload: {
                  menuPrefixList: menuPrefixList,
                  controllerType: controllerType,
                  menuTypeList: menuTypeList
                }
              });

            case 12:
              return _context.abrupt("return", code);

            case 13:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    queryLabelList: /*#__PURE__*/_regeneratorRuntime.mark(function queryLabelList(_, _ref3) {
      var put, call, res, res2;
      return _regeneratorRuntime.wrap(function queryLabelList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              put = _ref3.put, call = _ref3.call;
              _context2.next = 3;
              return call(_queryLabelList, {
                level: 'SITE',
                type: 'MENU'
              });

            case 3:
              res = _context2.sent;
              _context2.next = 6;
              return call(_queryLabelList, {
                level: 'TENANT',
                type: 'MENU'
              });

            case 6:
              res2 = _context2.sent;
              _context2.next = 9;
              return put({
                type: 'updateStateReducer',
                payload: {
                  siteLabelList: res,
                  tenantLabelList: res2
                }
              });

            case 9:
            case "end":
              return _context2.stop();
          }
        }
      }, queryLabelList);
    }),
    queryMenuLabel: /*#__PURE__*/_regeneratorRuntime.mark(function queryMenuLabel(_ref4, _ref5) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryMenuLabel$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call;
              _context3.next = 4;
              return call(_queryMenuLabel, payload);

            case 4:
              res = _context3.sent;
              return _context3.abrupt("return", res);

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, queryMenuLabel);
    }),
    querySearchLabels: /*#__PURE__*/_regeneratorRuntime.mark(function querySearchLabels(_ref6, _ref7) {
      var payload, put, call, response;
      return _regeneratorRuntime.wrap(function querySearchLabels$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              put = _ref7.put, call = _ref7.call;
              _context4.next = 4;
              return call(_querySearchLabels, payload);

            case 4:
              response = _context4.sent;

              if (!(response && !response.failed)) {
                _context4.next = 8;
                break;
              }

              _context4.next = 8;
              return put({
                type: 'updateStateReducer',
                payload: {
                  searchLabels: response
                }
              });

            case 8:
            case "end":
              return _context4.stop();
          }
        }
      }, querySearchLabels);
    }),
    // 查询菜单列表树形数据
    queryTreeList: /*#__PURE__*/_regeneratorRuntime.mark(function queryTreeList(_ref8, _ref9) {
      var params, put, call, res, response, rowKeys, getDataSource, dataSource;
      return _regeneratorRuntime.wrap(function queryTreeList$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              getDataSource = function _getDataSource() {
                var collections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
                return collections.map(function (n) {
                  var m = _objectSpread({}, n);

                  if (!_isEmpty(m.subMenus)) {
                    rowKeys.push(n.id);
                    m.subMenus = getDataSource(m.subMenus);
                  } else {
                    m.subMenus = null;
                  }

                  return m;
                });
              };

              params = _ref8.params;
              put = _ref9.put, call = _ref9.call;

              if (!organizationRoleLevel) {
                _context5.next = 9;
                break;
              }

              _context5.next = 6;
              return call(queryOrganizationMenuTree, organizationId, _objectSpread(_objectSpread({}, params), {}, {
                scope: 'CUSTOM'
              }));

            case 6:
              res = _context5.sent;
              _context5.next = 12;
              break;

            case 9:
              _context5.next = 11;
              return call(queryMenuTree, _objectSpread({}, params));

            case 11:
              res = _context5.sent;

            case 12:
              response = getResponse(res);
              rowKeys = [];
              /**
               * 组装新dataSource
               * @function getDataSource
               * @param {!Array} [collections = []] - 树节点集合
               * @param {string} parentName - 上级目录名称
               * @returns {Array} - 新的dataSourcee
               */

              dataSource = getDataSource(response);

              if (!response) {
                _context5.next = 18;
                break;
              }

              _context5.next = 18;
              return put({
                type: 'updateListReducer',
                payload: {
                  dataSource: dataSource,
                  rowKeys: rowKeys
                }
              });

            case 18:
              return _context5.abrupt("return", response);

            case 19:
            case "end":
              return _context5.stop();
          }
        }
      }, queryTreeList);
    }),
    // 检查目录编码是否存在
    checkMenuDirExists: /*#__PURE__*/_regeneratorRuntime.mark(function checkMenuDirExists(_ref10, _ref11) {
      var params, call, res;
      return _regeneratorRuntime.wrap(function checkMenuDirExists$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              params = _ref10.params;
              call = _ref11.call;
              _context6.next = 4;
              return call(_checkMenuDirExists, params);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", res);

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, checkMenuDirExists);
    }),
    // 查询值集
    queryCode: /*#__PURE__*/_regeneratorRuntime.mark(function queryCode(_ref12, _ref13) {
      var payload, put, call, response;
      return _regeneratorRuntime.wrap(function queryCode$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              put = _ref13.put, call = _ref13.call;
              _context7.next = 4;
              return call(_queryCode, payload);

            case 4:
              response = _context7.sent;

              if (!(response && !response.failed)) {
                _context7.next = 8;
                break;
              }

              _context7.next = 8;
              return put({
                type: 'setCodeReducer',
                payload: _defineProperty({}, payload.lovCode, response)
              });

            case 8:
            case "end":
              return _context7.stop();
          }
        }
      }, queryCode);
    }),
    // 查询上级目录
    queryParentDir: /*#__PURE__*/_regeneratorRuntime.mark(function queryParentDir(_ref14, _ref15) {
      var params, call, res, response;
      return _regeneratorRuntime.wrap(function queryParentDir$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              params = _ref14.params;
              call = _ref15.call;

              if (!organizationRoleLevel) {
                _context8.next = 8;
                break;
              }

              _context8.next = 5;
              return call(queryOrganizationDir, params, organizationId);

            case 5:
              res = _context8.sent;
              _context8.next = 11;
              break;

            case 8:
              _context8.next = 10;
              return call(queryDir, params);

            case 10:
              res = _context8.sent;

            case 11:
              response = getResponse(res);
              return _context8.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 13:
            case "end":
              return _context8.stop();
          }
        }
      }, queryParentDir);
    }),
    // 创建目录
    createDir: /*#__PURE__*/_regeneratorRuntime.mark(function createDir(_ref16, _ref17) {
      var params, call, res;
      return _regeneratorRuntime.wrap(function createDir$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              params = _ref16.params;
              call = _ref17.call;

              if (!organizationRoleLevel) {
                _context9.next = 8;
                break;
              }

              _context9.next = 5;
              return call(createOrganizationDir, params, organizationId);

            case 5:
              res = _context9.sent;
              _context9.next = 11;
              break;

            case 8:
              _context9.next = 10;
              return call(_createDir, params);

            case 10:
              res = _context9.sent;

            case 11:
              return _context9.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context9.stop();
          }
        }
      }, createDir);
    }),
    // 修改目录
    saveDir: /*#__PURE__*/_regeneratorRuntime.mark(function saveDir(_ref18, _ref19) {
      var params, call, res;
      return _regeneratorRuntime.wrap(function saveDir$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              params = _ref18.params;
              call = _ref19.call;

              if (!organizationRoleLevel) {
                _context10.next = 8;
                break;
              }

              _context10.next = 5;
              return call(saveOrganizationDir, params, organizationId);

            case 5:
              res = _context10.sent;
              _context10.next = 11;
              break;

            case 8:
              _context10.next = 10;
              return call(_saveDir, params);

            case 10:
              res = _context10.sent;

            case 11:
              return _context10.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context10.stop();
          }
        }
      }, saveDir);
    }),
    // 导入菜单
    importMenu: /*#__PURE__*/_regeneratorRuntime.mark(function importMenu(_ref20, _ref21) {
      var params, call, res;
      return _regeneratorRuntime.wrap(function importMenu$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              params = _ref20.params;
              call = _ref21.call;

              if (!organizationRoleLevel) {
                _context11.next = 8;
                break;
              }

              _context11.next = 5;
              return call(importOrganizationMenu, organizationId, params);

            case 5:
              res = _context11.sent;
              _context11.next = 11;
              break;

            case 8:
              _context11.next = 10;
              return call(_importMenu, params);

            case 10:
              res = _context11.sent;

            case 11:
              return _context11.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context11.stop();
          }
        }
      }, importMenu);
    }),
    // 查询菜单权限
    queryPermissions: /*#__PURE__*/_regeneratorRuntime.mark(function queryPermissions(_ref22, _ref23) {
      var params, call, res, response;
      return _regeneratorRuntime.wrap(function queryPermissions$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              params = _ref22.params;
              call = _ref23.call;
              _context12.next = 4;
              return call(_queryPermissions, params);

            case 4:
              res = _context12.sent;
              response = getResponse(res);
              return _context12.abrupt("return", {
                dataSource: (response || {}).content || [],
                pagination: createPagination(response || {})
              });

            case 7:
            case "end":
              return _context12.stop();
          }
        }
      }, queryPermissions);
    }),
    // 删除菜单
    deleteMenu: /*#__PURE__*/_regeneratorRuntime.mark(function deleteMenu(_ref24, _ref25) {
      var id, call, res;
      return _regeneratorRuntime.wrap(function deleteMenu$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              id = _ref24.id;
              call = _ref25.call;

              if (!organizationRoleLevel) {
                _context13.next = 8;
                break;
              }

              _context13.next = 5;
              return call(deleteOrganizationMenu, id, organizationId);

            case 5:
              res = _context13.sent;
              _context13.next = 11;
              break;

            case 8:
              _context13.next = 10;
              return call(_deleteMenu, id);

            case 10:
              res = _context13.sent;

            case 11:
              return _context13.abrupt("return", res);

            case 12:
            case "end":
              return _context13.stop();
          }
        }
      }, deleteMenu);
    }),
    // 查询菜单下已分解的权限集树
    queryPermissionSetTree: /*#__PURE__*/_regeneratorRuntime.mark(function queryPermissionSetTree(_ref26, _ref27) {
      var menuId, params, call, res, response, defaultExpandedRowKeys, getDataSource, dataSource;
      return _regeneratorRuntime.wrap(function queryPermissionSetTree$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              getDataSource = function _getDataSource2() {
                var collections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
                var parentId = arguments.length > 1 ? arguments[1] : undefined;
                var keyPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
                return collections.map(function (n) {
                  var m = _objectSpread(_objectSpread({}, n), {}, {
                    key: n.id
                  });

                  if (_isEmpty(m.keyPath)) {
                    defineProperty(m, 'keyPath', _isEmpty(keyPath) ? [] : keyPath);
                  }

                  m.keyPath = keyPath.concat(parentId);

                  if (!_isEmpty(m.subMenus)) {
                    m.subMenus = getDataSource(m.subMenus, m.id, m.keyPath);
                    defaultExpandedRowKeys.push(m.id);
                  } else {
                    m.subMenus = null;
                  }

                  return m;
                });
              };

              menuId = _ref26.menuId, params = _ref26.params;
              call = _ref27.call;
              _context14.next = 5;
              return call(_queryPermissionSetTree, menuId, params);

            case 5:
              res = _context14.sent;
              response = getResponse(res);
              defaultExpandedRowKeys = [];
              /**
               * 组装新dataSource
               * @function getDataSource
               * @param {!Array} [collections = []] - 树节点集合
               * @param {string} parentName - 上级目录名称
               * @returns {Array} - 新的dataSourcee
               */

              dataSource = getDataSource(response || []);
              return _context14.abrupt("return", {
                dataSource: dataSource,
                defaultExpandedRowKeys: defaultExpandedRowKeys
              });

            case 10:
            case "end":
              return _context14.stop();
          }
        }
      }, queryPermissionSetTree);
    }),
    // 启用禁用权限集及其下的所有子权限集
    setPermissionSetEnable: /*#__PURE__*/_regeneratorRuntime.mark(function setPermissionSetEnable(_ref28, _ref29) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function setPermissionSetEnable$(_context15) {
        while (1) {
          switch (_context15.prev = _context15.next) {
            case 0:
              payload = _ref28.payload;
              call = _ref29.call;
              _context15.next = 4;
              return call(_setPermissionSetEnable, payload);

            case 4:
              res = _context15.sent;
              return _context15.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context15.stop();
          }
        }
      }, setPermissionSetEnable);
    }),
    // 启用菜单/目录及其下的所有子权限集
    setMenuEnable: /*#__PURE__*/_regeneratorRuntime.mark(function setMenuEnable(_ref30, _ref31) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function setMenuEnable$(_context16) {
        while (1) {
          switch (_context16.prev = _context16.next) {
            case 0:
              payload = _ref30.payload;
              call = _ref31.call;
              _context16.next = 4;
              return call(_setPermissionSetEnable, payload);

            case 4:
              res = _context16.sent;
              return _context16.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context16.stop();
          }
        }
      }, setMenuEnable);
    }),
    // 查询权限集下可分配的所有权限
    queryPermissionsByMenuId: /*#__PURE__*/_regeneratorRuntime.mark(function queryPermissionsByMenuId(_ref32, _ref33) {
      var menuId, params, call, res, response;
      return _regeneratorRuntime.wrap(function queryPermissionsByMenuId$(_context17) {
        while (1) {
          switch (_context17.prev = _context17.next) {
            case 0:
              menuId = _ref32.menuId, params = _ref32.params;
              call = _ref33.call;
              _context17.next = 4;
              return call(_queryPermissionsByMenuId, menuId, params);

            case 4:
              res = _context17.sent;
              response = getResponse(res);
              return _context17.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 7:
            case "end":
              return _context17.stop();
          }
        }
      }, queryPermissionsByMenuId);
    }),
    queryPermissionsById: /*#__PURE__*/_regeneratorRuntime.mark(function queryPermissionsById(_ref34, _ref35) {
      var permissionSetId, params, call, res, response;
      return _regeneratorRuntime.wrap(function queryPermissionsById$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              permissionSetId = _ref34.permissionSetId, params = _ref34.params;
              call = _ref35.call;
              _context18.next = 4;
              return call(_queryPermissionsByMenuId, permissionSetId, params);

            case 4:
              res = _context18.sent;
              response = getResponse(res);
              return _context18.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 7:
            case "end":
              return _context18.stop();
          }
        }
      }, queryPermissionsById);
    }),
    // 查询权限集下已分配的权限
    queryPermissionsByIdAll: /*#__PURE__*/_regeneratorRuntime.mark(function queryPermissionsByIdAll(_ref36, _ref37) {
      var permissionSetId, params, call, res, response;
      return _regeneratorRuntime.wrap(function queryPermissionsByIdAll$(_context19) {
        while (1) {
          switch (_context19.prev = _context19.next) {
            case 0:
              permissionSetId = _ref36.permissionSetId, params = _ref36.params;
              call = _ref37.call;
              _context19.next = 4;
              return call(queryPermissionsByMenuIdAll, permissionSetId, params);

            case 4:
              res = _context19.sent;
              response = getResponse(res);
              return _context19.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 7:
            case "end":
              return _context19.stop();
          }
        }
      }, queryPermissionsByIdAll);
    }),
    // 查询权限集下已分配的Lov
    queryLovsByIdAll: /*#__PURE__*/_regeneratorRuntime.mark(function queryLovsByIdAll(_ref38, _ref39) {
      var permissionSetId, params, call, res, response;
      return _regeneratorRuntime.wrap(function queryLovsByIdAll$(_context20) {
        while (1) {
          switch (_context20.prev = _context20.next) {
            case 0:
              permissionSetId = _ref38.permissionSetId, params = _ref38.params;
              call = _ref39.call;
              _context20.next = 4;
              return call(queryLovsByMenuIdAll, permissionSetId, params);

            case 4:
              res = _context20.sent;
              response = getResponse(res);
              return _context20.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 7:
            case "end":
              return _context20.stop();
          }
        }
      }, queryLovsByIdAll);
    }),
    // 查询权限集下可分配的所有Lov
    queryLovByMenuId: /*#__PURE__*/_regeneratorRuntime.mark(function queryLovByMenuId(_ref40, _ref41) {
      var menuId, params, call, res, response;
      return _regeneratorRuntime.wrap(function queryLovByMenuId$(_context21) {
        while (1) {
          switch (_context21.prev = _context21.next) {
            case 0:
              menuId = _ref40.menuId, params = _ref40.params;
              call = _ref41.call;
              _context21.next = 4;
              return call(_queryLovByMenuId, menuId, params);

            case 4:
              res = _context21.sent;
              response = getResponse(res);
              return _context21.abrupt("return", {
                dataSource: response ? response.content : [],
                pagination: response ? createPagination(response) : {}
              });

            case 7:
            case "end":
              return _context21.stop();
          }
        }
      }, queryLovByMenuId);
    }),
    // 为权限集分配权限(包括Lov)
    assignPermissions: /*#__PURE__*/_regeneratorRuntime.mark(function assignPermissions(_ref42, _ref43) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function assignPermissions$(_context22) {
        while (1) {
          switch (_context22.prev = _context22.next) {
            case 0:
              payload = _ref42.payload;
              call = _ref43.call;
              _context22.next = 4;
              return call(_assignPermissions, payload);

            case 4:
              res = _context22.sent;
              return _context22.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context22.stop();
          }
        }
      }, assignPermissions);
    }),
    // 回收权限集的权限(包括Lov)
    deletePermissions: /*#__PURE__*/_regeneratorRuntime.mark(function deletePermissions(_ref44, _ref45) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deletePermissions$(_context23) {
        while (1) {
          switch (_context23.prev = _context23.next) {
            case 0:
              payload = _ref44.payload;
              call = _ref45.call;
              _context23.next = 4;
              return call(_deletePermissions, payload);

            case 4:
              res = _context23.sent;
              return _context23.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context23.stop();
          }
        }
      }, deletePermissions);
    }),
    // 查询客户化菜单
    queryOrganizationCustomMenu: /*#__PURE__*/_regeneratorRuntime.mark(function queryOrganizationCustomMenu(_ref46, _ref47) {
      var payload, call, put, res, response;
      return _regeneratorRuntime.wrap(function queryOrganizationCustomMenu$(_context24) {
        while (1) {
          switch (_context24.prev = _context24.next) {
            case 0:
              payload = _ref46.payload;
              call = _ref47.call, put = _ref47.put;
              _context24.next = 4;
              return call(_queryOrganizationCustomMenu, payload);

            case 4:
              res = _context24.sent;
              response = getResponse(res);

              if (!response) {
                _context24.next = 9;
                break;
              }

              _context24.next = 9;
              return put({
                type: 'updateStateReducer',
                payload: {
                  customMenu: {
                    list: response
                  }
                }
              });

            case 9:
            case "end":
              return _context24.stop();
          }
        }
      }, queryOrganizationCustomMenu);
    }),
    // 导出客户化菜单
    exportCustomMenu: /*#__PURE__*/_regeneratorRuntime.mark(function exportCustomMenu(_ref48, _ref49) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function exportCustomMenu$(_context25) {
        while (1) {
          switch (_context25.prev = _context25.next) {
            case 0:
              payload = _ref48.payload;
              call = _ref49.call;
              _context25.next = 4;
              return call(_exportCustomMenu, payload);

            case 4:
              res = _context25.sent;
              return _context25.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context25.stop();
          }
        }
      }, exportCustomMenu);
    }),
    // // 刷新菜单对应你 UI组件权限集
    // * refreshRoutePermissionSet({ payload }, { call }) {
    //   const { menuId } = payload;
    //   const res = yield call(refreshRoutePermissionSet, menuId);
    //   return getResponse(res);
    // },
    // 查询当前复制的节点及其子节点
    queryCopyMenuList: /*#__PURE__*/_regeneratorRuntime.mark(function queryCopyMenuList(_ref50, _ref51) {
      var params, call, res, response, defaultExpandedRowKeys, defaultSelectedRows, relatedRowKeys, traverseTree;
      return _regeneratorRuntime.wrap(function queryCopyMenuList$(_context26) {
        while (1) {
          switch (_context26.prev = _context26.next) {
            case 0:
              traverseTree = function _traverseTree(node) {
                if (!node) {
                  return;
                }

                defaultExpandedRowKeys.push(node.id);
                relatedRowKeys.push({
                  id: node.id,
                  parentId: node.parentId
                });
                defaultSelectedRows.push(node);

                if (node.subMenus && node.subMenus.length > 0) {
                  for (var i = 0; i < node.subMenus.length; i++) {
                    traverseTree(node.subMenus[i]);
                  }
                }
              };

              params = _ref50.params;
              call = _ref51.call;
              _context26.next = 5;
              return call(_queryCopyMenuList, params);

            case 5:
              res = _context26.sent;
              response = getResponse(res);
              defaultExpandedRowKeys = [];
              defaultSelectedRows = [];
              relatedRowKeys = [];

              if (!response) {
                _context26.next = 13;
                break;
              }

              response.forEach(function (item) {
                return traverseTree(item);
              });
              return _context26.abrupt("return", {
                copyMenuList: response || [],
                copyMenuListDefaultRowKeys: defaultExpandedRowKeys || [],
                relatedRowKeys: relatedRowKeys || []
              });

            case 13:
            case "end":
              return _context26.stop();
          }
        }
      }, queryCopyMenuList);
    }),
    // 复制并创建菜单
    copyMenu: /*#__PURE__*/_regeneratorRuntime.mark(function copyMenu(_ref52, _ref53) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function copyMenu$(_context27) {
        while (1) {
          switch (_context27.prev = _context27.next) {
            case 0:
              payload = _ref52.payload;
              call = _ref53.call;
              _context27.next = 4;
              return call(_copyMenu, payload);

            case 4:
              res = _context27.sent;
              return _context27.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context27.stop();
          }
        }
      }, copyMenu);
    })
  },
  reducers: {
    setCodeReducer: function setCodeReducer(state, _ref54) {
      var payload = _ref54.payload;
      return _objectSpread(_objectSpread({}, state), {}, {
        code: Object.assign(state.code, payload)
      });
    },
    updateStateReducer: function updateStateReducer(state, _ref55) {
      var payload = _ref55.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    },
    updateListReducer: function updateListReducer(state, _ref56) {
      var payload = _ref56.payload;
      return _objectSpread(_objectSpread({}, state), {}, {
        list: _objectSpread(_objectSpread({}, state.list), payload)
      });
    }
  }
};